"""请求网页"""
import time

import content as content
import requests
import re
import os

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
}
response = requests.get('https://www.vmgirls.com/12985.html', headers=headers)
# print(response.request.headers)
# print(response.text)
html = response.text
"""解析网页"""
dir_name = re.findall('<h1 class="post-title mb-3">(.*?)</h1>', html)[-1]
if not os.path.exists(dir_name):
    os.mkdir(dir_name)
urls = re.findall('<a href="(.*?)" alt=".*?" title=".*?">', html)
print(urls)
"""保存图片"""
for url in urls:
    time.sleep(1)
    # 图片的名字
    file_name = url.split('/')[-1]
    # https://t.cdn.ink/image/2019/10/E1DF3578-2865-430B-9518-AA7EB7C05459-1-scaled.jpeg
    response = requests.get('https:' + url, headers=headers)
    with open(dir_name + '/' + file_name, 'wb') as f:
        f.write(response.content)
